<?php
/** 
 * 权限规则模型扩展类
 *
 * @author   xg
 * @date     2019-09-20
 */

namespace app\base\model;

use think\Db;
use think\Model;
use think\facade\Log;
use app\common\model\AuthRule;

class AuthRuleModel extends AuthRule
{

    /**
     * 根据规则路径获取规则
     * @param   string  $path   规则路径
     * @return  array           规则数据
     */
    public function getOneByPath($path)
    {
        $data = $this->where("path = '".$path."'")->find();

        if (empty($data)) {
            return [];
        }

        return $data;
    }

    /**
     * 主键获取下一级子规则
     * @param   number  $rule_id    规则id
     * @return  array               规则数据
     */    
    public function getChildByPk($rule_id)
    {
        $data = $this->where('pid = '.$rule_id)->select();

        if ($data->isEmpty()) {
            return [];
        }

        return $data;
    }

}
